<%@page import="java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%request.setCharacterEncoding("UTF-8"); %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录成功</title>
</head>
<body>
<%
	//获取用户输入的用户名和密码
	String userName = request.getParameter("userName");
	String psd = request.getParameter("psd");
	
	String url = "jdbc:mysql://localhost:3306/wacai?serverTimezone=Asia/Shanghai";
	String dbUserName = "root";
	String dbPsd = "root1234";
	Connection connection = null;
	PreparedStatement pstmt = null;
	String sql = null;
	if(userName!=null && psd!=null){
		try{
			Class.forName("com.mysql.jdbc.Driver");//加载JDBC驱动程序
		}catch(ClassNotFoundException e){
			out.println("加载驱动器类时出现异常");
		}
	
	try{
		connection = DriverManager.getConnection(url,dbUserName,dbPsd);//连接数据库
		sql = "select * from user where userName=? and password=?";
		pstmt = connection.prepareStatement(sql);
		pstmt.setString(1,userName);
		pstmt.setString(2,psd);
		
		ResultSet resultSet = pstmt.executeQuery();
		if(resultSet.next()){
			out.print("<script type='text/javascript'>alert('登录成功！');</script>");
			response.setHeader("Refresh","0.1;url=home.jsp");
		}else{
			out.print("<script type='text/javascript'>alert('账号或密码错误，登录失败！');</script>");
			response.setHeader("Refresh","0.1;url=index.jsp");
		}		
		pstmt.close();
		connection.close();
	}catch(SQLException e){
			
		}}%>
</body>
</html>